$(document).ready(function(){		
	$("#addUser").val(username);
	initCate();
	var src = tl_config.last_url;	
	var i = src.indexOf('?');
	var j =src.indexOf('&tsnName=');
	var m=src.indexOf('&md=');
	
	if(i!=-1){		
		var id = src.substring(i+4,j);		
		var parentTsnName=src.substring(j+9,m);		
		
		$("#parentTsnId").val(id);
		$("p#parentTsnName").text(parentTsnName);		
	}	
	
	//表单验证
	var validate = $("#fromChildNavigationAdd").validate({		   
			rules:{					
				xName:{
					  required:true,
				      remote: { 
		                   url: server_url+'/rest/childNavigation/checkXName.do?timestamp='+Math.random()+ '&token=' + token,
		                   type: "post",
		                   dataType: "json", 
		                   data: {	
		                	       parentTsnId: function() { return $("#parentTsnId").val();},
		                	       xName: function() { return $("#xName").val();}
		                         } 
		               },
		               stringMaxLength:30
				}
			},
			messages:{				
				xName:{
				           required:"该值不能为空！",
	                       remote:"筛选值已存在，请重新输入!",
	                       stringMaxLength:"最多能输入30个字符！"
	                   }
			},
			submitHandler:function(){
				sub();
			},
			errorPlacement: function(error, element) {
				if ( element.is(":radio") )
					error.appendTo ( element.parent() );
				else if ( element.is(":checkbox") )
					error.appendTo ( element.parent() );
				else if ( element.is("input[name=captcha]") )
					error.appendTo ( element.parent() );
				else
					error.insertAfter(element);
			},
			validClass : 'rightValidate',
		    success: function(label) {
			   label.html("&nbsp;").text(" ") ;
		    }
	 });	
	
});


//提交
function sub(){	
	if($("#fromChildNavigationAdd").valid()){
		$.ajax({			
			url:server_url+'rest/childNavigation/ChildNavigationAdd.do?ran='+Math.random()+ '&token=' + token,
			type:'post',
			data:$("#fromChildNavigationAdd").serialize(),
			success:function(data){
				easyDialog.open({container:{header:'温馨提示',content:data.retMsg},autoClose : 2000});
				back();
			}
		});
	}
}


function back(){
    var url="getchildNavigationListPage.do?ran="+Math.random();
	tl_config.loadToWorkArea(url);
}
//文本框字数动态显示

function submitCommit(){
	$("#fromChildNavigationAdd").submit();
}



//开窗选择分类
function toOpenPop(){	
	easyDialog.open(
	{
		  container :'bm_box',
		  fixed : false
	}	
	);	
	
}

function closeBtn(){
	$(".l_pageUpDown").remove();  
}

function sureBtn(cateId,cateName){
	$("#tsnId").val(cateId);
	$("#xName").val(cateName);
	easyDialog.close();
}

function initCate(){	
	gridObj = $.fn.bsgrid.init('g_tabYeh', {
		ajaxType : 'get',
		url :  server_url+'/rest/productCate/productCateList.do?ran=' + Math.random() + '&token=' + token,
		autoLoad : true,
		pageSizeSelect : true,
		stripeRows : true,
		pageSize : 10,
		displayBlankRows : false,
		isProcessLockScreen : true,
		rowSelectedColor : false,
		showPageToolbar:true
	});
}

function operate(record, rowIndex, colIndex, options) {	
	return '<a href="javascript:sureBtn(\'' + gridObj.getRecordIndexValue(record, 'cateId') + '\''+'\,\''+ gridObj.getRecordIndexValue(record, 'cateName') +'\');">确认选择</a>';
}
